from tronpy import Tron
from tronpy.keys import PrivateKey

# 初始化 Tron 客户端
client = Tron()

# 替换为你的私钥
# private_key_str = "967208da3a945152835838fa3d0c70ecb808fd2d932f3da0d16c16543f0aa3f1"
# private_key = PrivateKey(bytes.fromhex(private_key_str))

# # 获取地址
# address = private_key.public_key.to_base58check_address()

address="TMMQNYWGzTKrWJQXeEWhS94PouesPt6Quz"
# 查询 TRX 余额
trx_balance = client.get_account_balance(address)
trx_balance_str = str(trx_balance)
# print(f"aa: {str(trx_balance)}")
print(f"TRX 余额: {trx_balance} TRX")
print(f"TRX 余额Str: {trx_balance_str} TRX")

# 查询 USDT 余额
contract_address = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"  # TRC20 USDT 合约地址
contract = client.get_contract(contract_address)

if contract:
    usdt_balance = contract.functions.balanceOf(address) / 1_000_000  # USDT 精度为 6
    print(f"USDT 余额: {usdt_balance} USDT")
else:
    print("无法找到 USDT 合约，请检查网络连接或合约地址是否正确。")